﻿using System;
using System.ComponentModel;
using System.Diagnostics;

namespace Arch.Model
{
    public class ModelObject : IModelObject
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public virtual void RaisePropertyChanged(string propertyName)
        {
            VerifyPropertyName(this, propertyName);
            PropertyChangedEventHandler propertyChanged = PropertyChanged;
            if (propertyChanged != null)
            {
                propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        [Conditional("DEBUG"), DebuggerStepThrough]
        public static void VerifyPropertyName(object obj, string propertyName)
        {
            if (obj.GetType().GetProperty(propertyName) == null)
            {
                throw new ArgumentException("Property not found", propertyName);
            }
        }
    }
}
